package com.kws.tool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kws.common.core.domain.R;
import com.kws.common.log.annotation.Log;
import com.kws.common.log.enums.BusinessType;
import com.kws.tool.dto.CreateMeasureToolRq;
import com.kws.tool.dto.QueryMeasureToolRq;
import com.kws.tool.dto.info.QueryMeasureToolInfo;
import com.kws.tool.entity.TbMeasureTool;
import com.kws.tool.service.MeasureToolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <b>MeasureToolController</b>
 *
 * @description: MeasureToolController <br>
 * @date: 2024/11/21 13:10 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "测算工具管理模块")
@RestController
public class MeasureToolController {
    private static final Logger logger = LoggerFactory.getLogger(MeasureToolController.class);

    @Autowired
    private MeasureToolService measureToolService;

    @ApiOperation("分页查询测算工具列表")
    @PostMapping("/query/measureTool/page")
    public R<Page<TbMeasureTool>> queryMeasureToolPage(@RequestBody QueryMeasureToolRq rq){
        Page<TbMeasureTool> pageInfo = measureToolService.queryMeasureToolPage(rq);
        return R.ok(pageInfo);
    }

    @ApiOperation("添加测算工具信息")
    @Log(title = "添加测算工具", businessType = BusinessType.INSERT)
    @PostMapping("/create/measureTool")
    public R createMeasureTool(@RequestBody CreateMeasureToolRq rq){
        return measureToolService.createMeasureTool(rq);
    }

    @ApiOperation("根据ID查询测算工具详情")
    @GetMapping("/query/measureTool/byId")
    public R<QueryMeasureToolInfo> queryMeasureToolById(@RequestParam Long id){
        QueryMeasureToolInfo info = measureToolService.queryMeasureToolById(id);
        return R.ok(info);
    }

    @ApiOperation("修改测算工具内容")
    @Log(title = "修改测算工具", businessType = BusinessType.UPDATE)
    @PostMapping("/update/measureTool")
    public R updateMeasureTool(@RequestBody QueryMeasureToolInfo info){
        return measureToolService.updateMeasureTool(info);
    }

    @ApiOperation("根据ID删除测算工具")
    @Log(title = "删除测算工具", businessType = BusinessType.DELETE)
    @GetMapping("/delete/measureTool/byId")
    public R deleteMeasureToolById(@RequestParam Long id){
        boolean status = measureToolService.deleteMeasureToolById(id);
        return R.ok(status);
    }

    @ApiOperation("根据ID修改测算工具状态")
    @Log(title = "测算工具状态", businessType = BusinessType.DELETE)
    @GetMapping("/update/measureToolStatus/byId")
    public R updateMeasureToolStatusById(@RequestParam Long id,@RequestParam String status){
        boolean b = measureToolService.updateMeasureToolStatusById(id,status);
        return R.ok(b);
    }
}
